﻿//提供了卖家接收退款，退款留言等功能 


using System;
using Top.Api.Response;
using Top.Api.Request;
using Top.Api.Util;

namespace TaobaoAPIDAO.TopApiDao
{
    public class RefundApiDao : BaseTopApiDao
    {
        #region public void TaobaoRefundGet(string sessionKey, long RefundId) 单笔退款详情
        /// <summary>
        /// 单笔退款详情
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="RefundId">退款单号 </param>
        public void TaobaoRefundGet(string sessionKey, long RefundId)
        {
            RefundGetRequest req = new RefundGetRequest();
            req.Fields = RefundApiFiled.RefundApiField;
            req.RefundId = RefundId;
            RefundGetResponse response = myclient.Execute(req, sessionKey);
        }

        #endregion

        #region public void TaobaoRefundMessageAdd(string, long, string, FileItem) 创建退款留言/凭证
        /// <summary>
        /// 创建退款留言/凭证
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="RefundId">退款编号</param>
        /// <param name="Content">留言内容。最大长度: 400个字节 </param>
        /// <param name="fItem">图片（凭证）。类型: JPG,GIF,PNG;最大为: 500K </param>
        public void TaobaoRefundMessageAdd(string sessionKey, long RefundId, string Content, FileItem fItem)
        {
            RefundMessageAddRequest req = new RefundMessageAddRequest();
            req.RefundId = RefundId;
            req.Content = Content;
            if (!fItem.Equals(null))
            {
                req.Image = fItem;
            }
            
            RefundMessageAddResponse response = myclient.Execute(req, sessionKey);
        }

        #endregion

        #region public void TaobaoRefundMessagesGet(string sessionKey,long RefundId) 退款留言/凭证列表查询
        /// <summary>
        /// 退款留言/凭证列表查询
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="RefundId">退款单号 </param>
        public void TaobaoRefundMessagesGet(string sessionKey,long RefundId)
        {
            RefundMessagesGetRequest req = new RefundMessagesGetRequest();
            req.Fields = RefundMessageApiFiled.RefundMessageApiField;
            req.RefundId = RefundId;
            RefundMessagesGetResponse response = myclient.Execute(req, sessionKey);
        }

        #endregion

        #region public void TaobaoRefundRefuse(string, long, string, long, long, FileItem) 卖家拒绝退款
        /// <summary>
        /// 卖家拒绝退款
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="RefundId"></param>
        /// <param name="RefuseMessage"></param>
        /// <param name="Tid"></param>
        /// <param name="Oid"></param>
        /// <param name="fItem"></param>
        public void TaobaoRefundRefuse(string sessionKey, long RefundId, string RefuseMessage, long Tid, long Oid, FileItem fItem)
        {
            RefundRefuseRequest req = new RefundRefuseRequest();
            req.RefundId = RefundId;
            req.RefuseMessage = RefuseMessage;
            req.Tid = Tid;
            req.Oid = Oid;
            req.RefuseProof = fItem;
            RefundRefuseResponse response = myclient.Execute(req, sessionKey);
        }
        #endregion

        #region public void TaobaoRefundsApplyGet(string, string, string,string) 查询买家申请的退款列表
        /// <summary>
        /// 查询买家申请的退款列表
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="Status">退款状态</param>
        /// <param name="SellerNick">卖家昵称</param>
        /// <param name="Type">交易类型列表</param>
        public void TaobaoRefundsApplyGet(string sessionKey, string Status, string SellerNick,string Type)
        {
            RefundsApplyGetRequest req = new RefundsApplyGetRequest();
            req.Fields = "refund_id, tid, title, buyer_nick, seller_nick, total_fee, status, created, refund_fee";
            req.Status = Status;
            req.SellerNick = SellerNick;
            req.Type = Type;
            RefundsApplyGetResponse response = myclient.Execute(req, sessionKey);
        }
        #endregion

        #region public void TaobaoRefundsReceiveGet(string, string, string,string, DateTime, DateTime) 查询卖家收到的退款列表
        /// <summary>
        /// 查询卖家收到的退款列表
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <param name="Status"></param>
        /// <param name="BuyerNick"></param>
        /// <param name="Type"></param>
        /// <param name="StartModified"></param>
        /// <param name="EndModified"></param>
        public RefundsReceiveGetResponse TaobaoRefundsReceiveGet(string sessionKey, DateTime StartModified, DateTime EndModified, string Status, string BuyerNick, 
            string Type)
        {
            RefundsReceiveGetRequest req = new RefundsReceiveGetRequest();
            req.Fields = RefundApiFiled.RefundApiField;//"refund_id, tid, title,buyer_nick, seller_nick, total_fee, status, created, refund_fee";
            if (!string.IsNullOrEmpty(Status))
            {
                req.Status = Status;
            }
            if (!string.IsNullOrEmpty(BuyerNick))
            {
                req.BuyerNick = BuyerNick;
            }
            if (!string.IsNullOrEmpty(Type))
            {
                req.Type = Type;
            }
            
            req.StartModified = StartModified;
            req.EndModified = EndModified;

            RefundsReceiveGetResponse response = myclient.Execute(req, sessionKey);
            return response;
        }
        #endregion


    }
}
